package org.rency.crawler.domain;

import java.io.Serializable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.rency.common.utils.domain.Extension;
import org.rency.crawler.common.CrawlerConstants;
import org.rency.crawler.common.enums.HttpMethod;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/20 17:41<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/20 17:41
 */
public class FetchRequest implements Serializable, CrawlerConstants {

  /**
   * 抓取编号(取值来自fetchUri)
   */
  @Size(max = LENGTH_FETCH_NO,message = "抓取编号最大长度为"+LENGTH_FETCH_NO)
  private String            fetchNo;

  /**
   * 抓取地址
   */
  @NotNull(message = "抓取地址不能为空")
  @Size(max = LENGTH_FETCH_TARGET_URI,message = "抓取地址最大长度为"+LENGTH_FETCH_TARGET_URI)
  private String            fetchUri;

  /**
   * 域名标识
   */
  @Size(max = LENGTH_FETCH_NO,message = "抓取域名编号最大长度为"+LENGTH_FETCH_NO)
  private String            fetchHost;

  /**
   * 域名地址
   */
  @Size(max = LENGTH_FETCH_TARGET_URI,message = "抓取域名地址最大长度为"+LENGTH_FETCH_TARGET_URI)
  private String            hostAddr;

  /**
   * 请求方式
   */
  @NotNull(message = "HTTP请求方法不能为空")
  private HttpMethod        httpMethod;

  /**
   * 请求参数
   */
  private Extension         parameter;

  public String getFetchNo() {
    return fetchNo;
  }

  public void setFetchNo(String fetchNo) {
    this.fetchNo = fetchNo;
  }

  public String getFetchUri() {
    return fetchUri;
  }

  public void setFetchUri(String fetchUri) {
    this.fetchUri = fetchUri;
  }

  public String getFetchHost() {
    return fetchHost;
  }

  public void setFetchHost(String fetchHost) {
    this.fetchHost = fetchHost;
  }

  public String getHostAddr() {
    return hostAddr;
  }

  public void setHostAddr(String hostAddr) {
    this.hostAddr = hostAddr;
  }

  public HttpMethod getHttpMethod() {
    return httpMethod;
  }

  public void setHttpMethod(HttpMethod httpMethod) {
    this.httpMethod = httpMethod;
  }

  public Extension getParameter() {
    return parameter;
  }

  public void setParameter(Extension parameter) {
    this.parameter = parameter;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((fetchNo == null) ? 0 : fetchNo.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj){
      return true;
    }
    if (obj == null){
      return false;
    }
    if (getClass() != obj.getClass()){
      return false;
    }
    FetchRequest other = (FetchRequest) obj;
    if (fetchNo == null) {
      if (other.fetchNo != null){
        return false;
      }
    } else if (!fetchNo.equals(other.fetchNo)){
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  }
}
